Skip to content

helios: allow persistent workers on rank 0 of local multi-rank cores - #640

Open
original-el8 wants to merge 1 commit into
NVIDIA:mainfrom
liquidgravityai:pr/helios-rank0-persistent-worker
Open

original-el8 wants to merge 1 commit into
NVIDIA:mainfrom
liquidgravityai:pr/helios-rank0-persistent-worker

Conversation

@original-el8

Copy link
Copy Markdown
Collaborator

Why

Helios previously rejected persistent_workers whenever a core contained more than one rank, even when only rank 0 of a local multi-rank deployment carried a persistent worker and peer ranks carried none. That restriction blocked local multi-GPU cores from combining a rank-0 persistent worker (such as a GPU-side mover) with plain peer ranks under ThreadedExecutor. Multi-host socket clusters and peer ranks (rank > 0) still do not support persistent workers and must remain explicitly rejected.

What changed

  • helios/src/runtime_core/model.rs:
    • Before: validate_persistent_worker_topology rejected any core set with cores.len() > 1 or cluster.is_some() if any rank had non-empty persistent_workers.
    • After: validate_persistent_worker_topology allows cores.first() (rank 0) to carry a persistent worker on local cores (cluster.is_none()), while rejecting peer ranks (cores.iter().skip(1)) or clustered cores (has_rank0_worker && cluster.is_some()) with "persistent workers are only supported on rank 0 of a local core".
    • Updated persistent_worker_topology_rejects_peer_rank_and_cluster_cores to verify [worker, plain] passes while [worker, worker], [plain, worker], and [worker] with a cluster descriptor fail.
  • helios/src/runtime_core/selection.rs:
    • Before: LoadOptions::select rejected !execution.persistent_workers.is_empty() && multi_rank.
    • After: LoadOptions::select checks rank > 0, retaining rank 0's persistent worker graph on local multi-rank cores while rejecting peer-rank persistent workers with "persistent workers are only supported on rank 0".
    • Updated selected_graphs_retain_rank0_persistent_worker_and_reject_peer_or_multiple_workers to cover [worker_core(), core()], [worker_core(), worker_core()], and [core(), worker_core()].
  • helios/src/execution/threaded.rs:
    • Before: ThreadedExecutor::new rejected !manifest.persistent_workers.is_empty() alongside peer workers, and same_layout(a, b) required a.persistent_workers and b.persistent_workers to match.
    • After: ThreadedExecutor::new rejects only peer ranks with non-empty persistent_workers (ranks.iter().any(|rank| !rank.persistent_workers.is_empty())), and same_layout(a, b) requires b.persistent_workers.is_empty() so rank 0's persistent worker does not fail peer layout comparison.
    • Added rank_layout_permits_persistent_worker_only_on_rank_zero.
  • docs/runtime-core-design.md:
    • Updated the Execution.persistent_workers topology specification to match rank-0 support on local cores and peer/cluster rejection.

Result

Local multi-rank cores can load, select, and initialize rank-0 persistent workers alongside plain peer ranks, while peer-rank persistent workers, multiple workers per rank, and multi-host cluster persistent workers continue to fail validation explicitly.

Verification

Executed CPU-only (CUDA_VISIBLE_DEVICES="") against helios/Cargo.toml (flare-helios):

  • cargo test --locked --manifest-path helios/Cargo.toml -p flare-helios --features runtime-core,server --lib execution::: 133 passed, 0 failed, 2 ignored (CUDA-gated tests).
  • cargo test --locked --manifest-path helios/Cargo.toml -p flare-helios --features runtime-core,server --lib runtime_core::: 186 passed, 0 failed, 11 ignored (CUDA-gated tests).
  • cargo test --locked --manifest-path helios/Cargo.toml -p flare-helios --features runtime-core --lib: 1,167 passed, 0 failed, 34 ignored.

Limitations: CUDA-gated Green Context tests (#[ignore]) and live multi-GPU core loading/execution with a persistent worker were not executed in this CPU-only check.

Discord: el8

Why:
Helios rejected persistent_workers whenever a core contained more than one rank, preventing local multi-GPU deployments from running a rank-0 persistent worker alongside plain peer ranks under ThreadedExecutor. Peer ranks (rank > 0) and multi-host socket clusters still do not support persistent workers and must remain explicitly rejected.

What:
- helios/src/runtime_core/model.rs:
  - Before: validate_persistent_worker_topology rejected any core slice with cores.len() > 1 or cluster.is_some() when any rank declared persistent_workers.
  - After: validate_persistent_worker_topology permits cores.first() (rank 0) to declare persistent_workers on local cores (cluster.is_none()), while rejecting peer ranks (cores.iter().skip(1)) or clustered cores (has_rank0_worker && cluster.is_some()) with "persistent workers are only supported on rank 0 of a local core".
  - Updated persistent_worker_topology_rejects_peer_rank_and_cluster_cores to cover [worker, plain], [worker, worker], [plain, worker], and [worker] with cluster metadata.
- helios/src/runtime_core/selection.rs:
  - Before: LoadOptions::select rejected !execution.persistent_workers.is_empty() && multi_rank.
  - After: LoadOptions::select rejects !execution.persistent_workers.is_empty() && rank > 0 with "persistent workers are only supported on rank 0", retaining rank 0's persistent worker graph on local multi-rank cores.
  - Updated selected_graphs_retain_rank0_persistent_worker_and_reject_peer_or_multiple_workers.
- helios/src/execution/threaded.rs:
  - Before: ThreadedExecutor::new rejected !manifest.persistent_workers.is_empty() as well as peer workers, and same_layout(a, b) required a.persistent_workers and b.persistent_workers to match.
  - After: ThreadedExecutor::new rejects only ranks.iter().any(|rank| !rank.persistent_workers.is_empty()), and same_layout(a, b) checks !b.persistent_workers.is_empty() so rank 0's persistent worker does not fail peer layout validation.
  - Added rank_layout_permits_persistent_worker_only_on_rank_zero.
- docs/runtime-core-design.md:
  - Updated Execution.persistent_workers topology wording to match rank-0 support on local cores and peer/cluster rejection.

Result:
Local multi-rank cores can validate, select, and initialize rank-0 persistent workers alongside plain peer ranks while rejecting peer-rank, multi-worker, and multi-host cluster persistent workers.

Verification and limitations:
- Executed CPU-only (CUDA_VISIBLE_DEVICES="") against helios/Cargo.toml (flare-helios):
  - cargo test --locked --manifest-path helios/Cargo.toml -p flare-helios --features runtime-core,server --lib execution:: -> 133 passed, 0 failed, 2 ignored (CUDA-gated).
  - cargo test --locked --manifest-path helios/Cargo.toml -p flare-helios --features runtime-core,server --lib runtime_core:: -> 186 passed, 0 failed, 11 ignored (CUDA-gated).
  - cargo test --locked --manifest-path helios/Cargo.toml -p flare-helios --features runtime-core --lib -> 1,167 passed, 0 failed, 34 ignored.
- Limitations: CUDA-gated Green Context tests (#[ignore]) and live multi-GPU core loading/execution with a persistent worker were not executed in this CPU-only check.

Design-Signed-Off-By: Jason Cook <1637905+original-el8@users.noreply.github.com>; design-review=2e5b
@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 640.
Case File Intake Report

Future reviews will auto-run 90 minutes after code updates are pushed.

  • Re-review sooner: Call @flare-autobot after push.
  • Opt-out: Include #autobot:ignore in the PR or any comment.

@flare-autobot flare-autobot added enhancement New feature or request triage:review Proposed change needs code review; this does not imply merge readiness. labels Nov 30, 2026
@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

The predicate relaxations are narrow and model-agnostic, but the PR lifts PR #430's maintainer-imposed gate without exercising multi-rank initialization, partial-startup-failure, or failure-abandonment paths, leaves helios/manifest.md contradicting the code, and exposes unvalidated cooperative SM-partition asymmetry across ranks.

  • Blockers: 1 · Should fix: 3 · Subtract/Simplify: 3 · Nits: 3
Walkthrough
  • helios/src/runtime_core/model.rs:114-134, 1718-1772: Relaxed validate_persistent_worker_topology to allow rank 0 (cores.first()) to carry a persistent worker when cluster.is_none(), while rejecting peer ranks (cores.iter().skip(1)) and clustered cores with "persistent workers are only supported on rank 0 of a local core"; updated unit tests accordingly.
  • helios/src/runtime_core/selection.rs:224-225, 282-289, 650-721: Removed let multi_rank = cores.len() > 1; and changed LoadOptions::select's guard from multi_rank to rank > 0 ("persistent workers are only supported on rank 0"); updated selection unit tests to retain rank 0's worker graph alongside a plain peer.
  • helios/src/execution/threaded.rs:632-636, 1292-1294, 1631-1651: Removed !manifest.persistent_workers.is_empty() from ThreadedExecutor::new so only peer manifests with workers are rejected, replaced same_layout's worker-field comparison with if !b.persistent_workers.is_empty() { return false; }, and added rank_layout_permits_persistent_worker_only_on_rank_zero.
  • docs/runtime-core-design.md:642-644: Updated the Execution.persistent_workers topology paragraph to state that local cores may declare a worker on rank 0 while peer ranks and multi-host cluster cores are rejected.
Merge Risk: Medium · up to b7a6204
  • Blast radius: Only affects local multi-rank (RankPeers::Threads) cores that declare Execution.persistent_workers on rank 0; single-rank cores, plain local multi-rank cores, and multi-host cluster cores are unchanged, and no serving hot path (DispatchRing, poll, wire formats) was altered.
  • Unexercised runtime surface: Admitting rank-0 workers on local multi-rank cores makes two untested multi-GPU/lifecycle interactions reachable: (1) asymmetric Green Context SM partitioning (partition_sms = Some(...) on rank 0 vs. None on peers) with cooperative kernels, and (2) ThreadedExecutor startup failure / GraphExecutor::abandon while rank 0's persistent worker is live.
  • Policy reversal without maintainer sign-off: PR Add Execution.persistent_workers green-context lifecycle #430's approval required keeping cores.len() > 1 rejected until multi-rank startup, teardown, and failure-abandonment (GraphExecutor::abandon, partial finish_startup failures) were implemented and tested.
Pre-merge checks: ✅ 2 passed · ⚠️ 2 warnings
Blockers (1)
  1. Unmet PR Add Execution.persistent_workers green-context lifecycle #430 multi-rank lifecycle condition and untested initialization/teardown paths (helios/src/execution/threaded.rs:632-636, 766-822, 1004-1012, 1631-1651; helios/src/execution/transport.rs:793-808, 979-990; helios/src/server/session.rs:96-101, 125-133):
    • Verified behavior/impact: In PR Add Execution.persistent_workers green-context lifecycle #430, @lukealonso required rejecting cores.len() > 1 explicitly until multi-rank coordination and failure-abandonment (GraphExecutor::abandon, partial finish_startup failures) are implemented and tested, or multi-rank startup and teardown are validated directly. This PR lifts the gate while adding zero tests that construct ThreadedExecutor::new with a rank-0 worker (the new test at threaded.rs:1631-1651 only calls same_layout, and helios/src/execution/tests.rs:1371-1373 only asserts peer rejection), leaving the PR's claim that local multi-rank cores can initialize rank-0 persistent workers unverified (docs/design-review.md:187-189). Furthermore, two concrete lifecycle hazards remain on the newly reachable multi-rank paths:
      1. Startup ordering (threaded.rs:766-775): result.local.finish_startup()? launches rank 0's persistent worker before confirming peers' Reply::Started. Because peer ranks cannot have persistent workers, peer finish_startup() does no CUDA work; if a peer fails startup, rank 0 has already launched the worker and peer-join cleanup (threaded.rs:802-810) calls std::process::abort() before result.local.close() at :813 runs.
      2. Failure abandonment (threaded.rs:1009-1012 -> transport.rs:979-990): When a poisoned multi-rank session or failed peer drain takes self.local.abandon(error), GraphExecutor::abandon forgets self.resources and returns Shutdown { drained: false, .. } without signaling the worker's stop_flag. DrainGuard (session.rs:125-133) then forgets NativeModel, so NativeResources::release_execution_resources() never runs either, leaving rank 0's persistent worker spinning on its SM partition until process exit (including in in-process Rust SDK consumers).
    • Concrete fix:
      • Receive Reply::Started from all peers before calling result.local.finish_startup()? in threaded.rs:766-775 so rank 0's worker never starts on a failed peer startup.
      • Decide and implement explicit abandonment semantics for a running rank-0 worker in GraphExecutor::abandon (e.g., best-effort control.stop() or non-blocking stop_flag = 1 write before forgetting resources, or document explicitly why it is intentionally left running).
      • Add a threaded CPU test (or test double via PersistentWorkerControl) exercising ThreadedExecutor::new with a rank-0 worker + plain peer(s), verifying start-once after peers are ready, clean stop on close(), and partial finish_startup / abandonment behavior; obtain maintainer sign-off from @lukealonso that Add Execution.persistent_workers green-context lifecycle #430's multi-rank condition is satisfied.
Should Fix (3)
  1. Unvalidated SM-partition asymmetry for cooperative TP collectives (helios/src/runtime_core/mod.rs:369-402, 763-781, 893-911, 1002-1017, 1335-1374; docs/same-process-tp.md:30-34):
    • Verified behavior/impact: NativeResources creates a primary context + GreenContextPartition only when a rank declares a persistent worker (now rank 0 only), setting partition_sms = Some(partition.compute_sm_count) (mod.rs:906), while peer ranks use cuCtxCreate_v2 with partition_sms = None (mod.rs:397-401, 910). At mod.rs:1002-1006, status == 0 && partition_sms.is_some() triggers clamp_cooperative_launch on rank 0 even when the cooperative attribute restored cleanly, clamping rank 0's grid to blocks_per_sm * compute_sm_count while peers keep their captured full-device grid. While single-GPU cooperative kernels tolerate largest-axis reduction (docs/runtime-core-design.md:906-915) and collectives whose grids already fit compute_sm_count are unaffected (mod.rs:144), any full-device cooperative collective expecting symmetric CTA counts across ranks will silently receive fewer CTAs on rank 0 than on peers — risking a barrier hang under docs/same-process-tp.md:32-33. Because no live multi-GPU test ran, neither cooperative grid symmetry nor VMM peer access (peer_access.rs:38-57) alongside a rank-0 Green Context has been verified.
    • Concrete fix: Either reject multi-rank loads when rank 0's cooperative clamp actually shrinks a grid relative to its peers (or require preparation validation that multi-rank cooperative collectives fit compute_sm_count without clamping and document that invariant in docs/same-process-tp.md:30-34 and docs/runtime-core-design.md:906-915), and validate with a live two-GPU run.
  2. Contradictory specification in helios/manifest.md (helios/manifest.md:89-95):
    • Verified behavior/impact: helios/manifest.md:92-95 still states: "Helios currently supports at most one persistent worker entry on single-rank cores; cores declaring more than one entry, multi-rank cores, and multi-host cluster cores declaring a persistent worker fail validation before execution." This directly contradicts both the code and docs/runtime-core-design.md:642-644.
    • Concrete fix: Reword helios/manifest.md:92-95 to match docs/runtime-core-design.md:642-644 (at most one entry on rank 0 of a local core; peer ranks and multi-host cluster cores fail validation).
  3. Run required --release verification gates and confirm green CI (docs/design-review.md:180-185; .github/workflows/native-serving.yml:56-77 (not opened)):
    • Verified behavior/impact: The PR body reports only CPU debug --lib runs on flare-helios, omitting --release, integration tests, and downstream crates (flare, flare-cli, heliopause) required by docs/design-review.md:180-185.
    • Concrete fix: Run cargo test --locked --release on helios --features runtime-core,server, flare, flare-cli, and heliopause, and ensure CI workflows pass on the updated head.
Subtract / Simplify (3)
  1. Delete the redundant worker check in same_layout (helios/src/execution/threaded.rs:1292-1294): ThreadedExecutor::new (threaded.rs:632-636) is the only non-test caller of same_layout (threaded.rs:639) and already rejects any peer rank with non-empty persistent_workers with the precise topology error before same_layout is called. Removing :1292-1294 eliminates unreachable production code and frees rank_layout_permits_persistent_worker_only_on_rank_zero (threaded.rs:1631-1651) to be replaced with a real ThreadedExecutor::new test.
  2. Delete the unreachable peer-rank worker check in LoadOptions::select (helios/src/runtime_core/selection.rs:285-289): select is pub(super) (selection.rs:76) with one production caller (helios/src/runtime_core/model.rs:441), which always runs after validate_persistent_worker_topology (model.rs:386). Deleting :285-289 removes both an unreachable production branch and the third divergent error string ("persistent workers are only supported on rank 0"). (If standalone defense-in-depth in select is explicitly desired, also check self.cluster_rank.is_some()—already present on LoadOptions at selection.rs:79—and unify the error message with model.rs:130.)
  3. Collapse the duplicated closure in validate_persistent_worker_topology (helios/src/runtime_core/model.rs:118-128): Replace the two identical 5-line closures (has_rank0_worker and has_peer_worker) with a single pass:
    let unsupported = cores.iter().enumerate().any(|(rank, core)| {
        core.execution
            .as_ref()
            .is_some_and(|execution| !execution.persistent_workers.is_empty())
            && (rank > 0 || cluster.is_some())
    });
    if unsupported { ... }
Nits (3)
  • helios/src/execution/tests.rs:1371: Update the now-stale comment // Multi-rank execution rejects persistent workers explicitly. to clarify that peer-rank persistent workers are rejected.
  • helios/src/execution/parallel.rs:124, 556: Update "persistent workers are only supported on single-rank cores" to "persistent workers are only supported on rank 0 of a local core" (or note socket TP specifically) so error wording stays consistent across execution backends.
  • helios/src/runtime_core/model.rs:1089-1092: NativeModel::drop iterates self.ranks.iter_mut().rev(), running release_execution_resources() (which unmaps device and mapped-host allocations) on peers before rank 0 stops its persistent worker. While normal ServingSession::close() stops the worker first via GraphExecutor::close(), stopping all persistent workers before unmapping any rank's allocations is clean defense-in-depth if NativeModel is ever dropped directly with a live worker.
Dropped on verification (4)
  • Correctness lens F6 claim that LoadOptions::select has no cluster state/argument: Verified false — LoadOptions already holds self.cluster_rank (helios/src/runtime_core/selection.rs:79). Dropped that premise; kept the simpler deletion/unification item under Subtract / Simplify.
  • Correctness lens F4 claim that same_layout newly became non-reflexive (!same_layout(&root, &root)): Verified overstated — same_layout was already non-reflexive for engram (helios/src/execution/threaded.rs:1276, asserted at :1620) and offload (:1283). Replaced with the stronger verified finding that :1292-1294 is redundant with :632-636.
  • Overbroad framing of Correctness lens F1 implying all cooperative kernels deadlock under asymmetric SM partitions: Narrowed to the verified hazard — single-GPU cooperative kernels tolerate largest-axis reduction (docs/runtime-core-design.md:906-915) and collectives already fitting compute_sm_count are not shrunk (helios/src/runtime_core/mod.rs:144); the defect specifically affects full-device cooperative collectives assuming symmetric CTA counts across ranks (docs/same-process-tp.md:32-33).
  • Speculation about which CI workflow failed on b7a6204: CI logs are not accessible from this environment and the dossier noted approval gating on same-day PRs; dropped causal speculation while retaining the verified gap between reported CPU debug --lib runs and the required --release suite.

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request triage:review Proposed change needs code review; this does not imply merge readiness.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants